package hotelManagement.business_services;
import org.springframework.orm.hibernate3.support.*;
import org.hibernate.Hibernate;
import java.util.*;

public class RoomInfoDaoImpl extends HibernateDaoSupport implements RoomInfoDao{
	public RoomInfo get(String roomnumber){
		RoomInfo ri=(RoomInfo)getHibernateTemplate().load(RoomInfo.class, roomnumber);
		Hibernate.initialize(ri);
		return ri;
	}
	
	public List<RoomInfo> get(int type){
		List<RoomInfo> ri=getHibernateTemplate().find("from RoomInfo r where r.type="+type);
		return ri;
	}
	
	public void save(RoomInfo room){
		getHibernateTemplate().save(room);
	}
	
	public void delete(RoomInfo room){
		getHibernateTemplate().delete(room);
	}
	
	public void delete(String roomnumber){
		getHibernateTemplate().delete(get(roomnumber));
	}
	
	public void update(RoomInfo room){
		getHibernateTemplate().update(room);
	}
	
	public int getRoomNumber(){
		List roomList=getHibernateTemplate().find("select count(roomnumber) from RoomInfo");
		if(roomList==null)
			return 0;
		
		return (Integer)roomList.get(0);
	}
}
